import React from 'react';
import { PageContainer } from '@ant-design/pro-layout';
import { message } from 'antd';
import type { ProColumns } from '@ant-design/pro-table';
import ProTable from '@ant-design/pro-table';
import { getFrequencyCodesList } from '@/services/params/api';
import PermissionControl from '@/components/PermissionControl';
import { showMsg } from '@/utils/utils';
import BreadcrumbDept from '@/components/BreadcrumbDept';

const FrequencyCodesList: React.FC = () => {

  const columns: ProColumns<PARAMSAPI.FrequencyCodesItem>[] = [
    {
      title: '医嘱频次编码',
      dataIndex: 'frequency_id'
    },
    {
      title: '医嘱频次名称',
      dataIndex: 'frequency_name',
      search: false
    },
    {
      title: '输入串',
      dataIndex: 'input_str',
      search: false
    },
    {
      title: '频次次数',
      dataIndex: 'frequency',
      align: 'right',
      search: false
    },
    {
      title: '频次数目',
      dataIndex: 'frequency_num',
      align: 'right',
      search: false
    },
    {
      title: '频次单位',
      dataIndex: 'unit',
      valueType: 'select',
      valueEnum: {
        H: 'H（小时）',
        D: 'D（日）',
        W: 'W（周）',
        T: 'T（临时）'
      }
    },
    {
      title: '频次时间',
      dataIndex: 'frequency_time',
      search: false
    },
    {
      title: '持续频次标志',
      dataIndex: 'flag',
      search: false
    },
    {
      title: '执行表达式描述',
      dataIndex: 'frequency_desc',
      search: false
    }
  ];

  return (
    <PageContainer extra={[
     ]} breadcrumb={{}}>
      <div>
        <ProTable<PARAMSAPI.FrequencyCodesItem, PARAMSAPI.FrequencyCodesItem & COMMON.PageParams>
          rowKey="frequency_id"
          bordered
          className="frequency-codes-table"
          toolBarRender={false}
          request={async (params) => {
            params = Object.assign({}, params, { current: 1, pageSize: 10000});
            try {
              const data: PARAMSAPI.FrequencyCodesList = await getFrequencyCodesList(params);
              return {
                data: data.record_list,
                total: data.sum_record_num,
                success: true
              }
            } catch (error) {
              showMsg(error?.data?.errmsg);
              return {
                data: [],
                total: 0,
                success: true
              }
            }
          }}
          search={{
            span: 6,
            labelWidth: 100,
            optionRender: (searchConfig, formProps, dom) => {
              dom.shift();
              return [<PermissionControl key="search" action_id="800800000">{dom}</PermissionControl>];
            }
          }}
          pagination={false}
          columns={columns}
        />
      </div>
    </PageContainer>
  );
};
export default FrequencyCodesList;
